package me.leiusual.sharing.ui.useraccount.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.UserAccount

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountAdapter(
    private val type: String,
    private val clickListener: (UserAccount) -> Unit
) : RecyclerView.Adapter<UserAccountViewHolder>() {

  private var dataSet = emptyList<UserAccount>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserAccountViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_user_account, parent, false)
    return UserAccountViewHolder(type,itemView, clickListener)
  }

  override fun onBindViewHolder(holder: UserAccountViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(list: List<UserAccount>) {
    this.dataSet = list
    notifyDataSetChanged()
  }
}